/*
 * By: Werner Schuster (murphee)
 * 
 * Copyright (c) 2005-2006 Werner Schuster (murphee)
 * 
 * This file is part of the EclipseShell project. EclipseShell is subject 
 * to the Eclipse Public License (EPL) available at
 * http://www.eclipse.org/org/documents/epl-v10.php
 * or in the file /epl-v10.html in the source for other info
 * see the /eclipseshell.license file
 */
package net.sf.eclipseshell.editors;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

import sun.security.action.GetBooleanAction;

public class BeanshellSourceviewerConfiguration extends SourceViewerConfiguration {

	private DefaultScanner scanner_;
	private ColorManager colorManager_;
	private InterpreterTextHover textHover_;
	PresentationReconciler reconciler_;
	
	public BeanshellSourceviewerConfiguration(ColorManager colorManager) {
		this.colorManager_ = colorManager;
	}
	public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
		return new String[] {
			IDocument.DEFAULT_CONTENT_TYPE};
	}

	protected DefaultScanner getDefaultScanner() {
		if (scanner_ == null) {
			scanner_ = new DefaultScanner(colorManager_);
			scanner_.setDefaultReturnToken(
				new Token(
					new TextAttribute(
						colorManager_.getColor(DefaultColorConstants.DEFAULT))));
		}
		return scanner_;
	}

	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
		if(reconciler_ == null){
			reconciler_ = new PresentationReconciler();
			
			DefaultDamagerRepairer dr =
				new DefaultDamagerRepairer(getDefaultScanner());
			reconciler_.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
			reconciler_.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		}

		return reconciler_;
	}
	
	public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
		if(textHover_==null){
			textHover_ = new InterpreterTextHover();			
		}		
		return textHover_;
	}

}